package hn.cch

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object WordCount {
    def main(args: Array[String]): Unit = {

        val conf: SparkConf = new SparkConf()
        conf.setAppName("WordCount")
        // conf.setMaster("local")
        conf.setMaster("spark://centos:7077")
        conf.setJars(List("target/spark-scala.jar"))

        val sc: SparkContext = new SparkContext(conf)
        val textFile = sc.textFile("word")
        val rdd = textFile.flatMap(_.split(" ")).map((_, 1)).reduceByKey(_ + _)
        rdd.collect

        rdd.foreach(println)
        // rdd.saveAsTextFile("count")
        sc.stop()


    }

}